//
//  DTHomeFirstTableViewCell.m
//  DoThinkProperty
//
//  Created by YangJian on 15/9/23.
//  Copyright (c) 2015年 DoThink. All rights reserved.
//

#import "DTHomeFirstTableViewCell.h"
#import "DTHomeCollectionViewCell.h"
#import "Header.h"
@implementation DTHomeFirstTableViewCell

- (NSMutableArray *)imageArray
{
    if (_imageArray == nil) {
        _imageArray = [[NSMutableArray alloc] init];
    }
    return _imageArray;
}

- (void)creatImageAndTitleName
{
    for (int i = 0; i<8; i++)
    {
        //UIImage *image = [UIImage imageNamed:@"collectionImage1.png"];
       UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"collectionImage%d.png",i+1]];
        [self.imageArray addObject:image];
    }
    
    _titleArray =@[@"门禁管理",@"物业服务",@"信息留言",@"访客管理",@"生活缴费",@"快递服务",@"周边生活",@"智能物联"];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatImageAndTitleName];
        
        _flowLayout = [[UICollectionViewFlowLayout alloc] init];
        
        _mainCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200) collectionViewLayout:_flowLayout];
        _mainCollectionView.backgroundColor = [UIColor lightGrayColor];
        _mainCollectionView.delegate = self;
        _mainCollectionView.dataSource = self;
        [_mainCollectionView registerClass:[DTHomeCollectionViewCell class] forCellWithReuseIdentifier:@"collectionViewCell"];
        NSLog(@"%f",self.contentView.bounds.size.height);
        
        [self.contentView addSubview:_mainCollectionView];
    }
    return self;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _titleArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    DTHomeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionViewCell" forIndexPath:indexPath];
    
    cell.imageView.image =self.imageArray[indexPath.row];
    cell.label.text =_titleArray[indexPath.row];
    
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(SCREEN_WIDTH/4, self.contentView.bounds.size.height/2);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _mainCollectionView.frame = self.contentView.bounds;
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
